package com.yifan.planMode.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author YIFan
 * @Date 2020/12/8 13:16
 * @Version 1.0
 */

@Service
public class SimpleContext {

    //    @Autowired
    private final Map<String, Strategy> strategyMap = new ConcurrentHashMap<>();

//    Key为bean的名字，value为 Strategy 这个接口实现类的 bean
    public SimpleContext(Map<String, Strategy> strategyMap) {
        this.strategyMap.clear();
        strategyMap.forEach((k, v) -> {
            this.strategyMap.put(k, v);
            System.err.println("k =>" + k + "\t v =>" + v);
        });
    }

    public String getResource(String id) {
        return strategyMap.get(id).say(id);
    }


}
